package com.yxhl.km.http.cookie;

import com.yxhl.km.MyApplication;
import com.yxhl.km.module.utils.Constants;
import com.yxhl.km.module.utils.SharedPreferencesUtils;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * Created by 张亚楠 on 2018/5/18.
 * 拦截器Interceptor
 */

public class CookiesInterceptor implements Interceptor {
    @Override
    public Response intercept(Chain chain) throws IOException {
        Request.Builder builder = chain.request().newBuilder();
        String cookie = (String) SharedPreferencesUtils.getParam(MyApplication.mContext, Constants.COOKIE, "");
        if (cookie != null) {
            builder.addHeader("Cookie", cookie);
        }
        return chain.proceed(builder.build());
    }

}
